/*
 * @Author: shiyue 2647472992@qq.com
 * @Date: 2024-08-26 20:22:10
 * @LastEditors: shiyue 2647472992@qq.com
 * @LastEditTime: 2024-08-26 20:46:23
 * @FilePath: \SelectSort\SelectSort.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <vector>
#include <ctime>
using namespace std;


class SelectSort
{
public:
    SelectSort(vector<int>& array)
    :_array(array)
    ,_size(array.size())
    ,_capacity(array.size())
    {}

    ~SelectSort()
    {}

    void PrintArray()
    {
        int n = _size;
        for (int i = 0; i < n; ++i)
        {
            cout << _array[i] << " ";
        }
            cout << endl;
    }

    void Sort()
    {
        int left = 0, right = _size - 1;
        while (left < right)
        {
            int max = left, min = left;
            for (int i = left; i <= right; ++i)
            {
                if (_array[min] > _array[i])
                {
                    min = i;
                }

                if (_array[max] < _array[i])
                {
                    max = i;
                }
            }
            swap(_array[left], _array[min]);
            if (max == left)
            {
                max = min;
            }
            swap(_array[right], _array[max]);
            ++left;
            --right;

        } 

    }
private:
    vector<int> _array;
    int _size;
    int _capacity;

};

int main()
{
    vector<int> array(10, 8);
    srand(time(nullptr));
    for (auto &e : array)
    {
        e = rand() % 100;
    }
    SelectSort test(array);
    test.PrintArray();
    test.Sort();
    test.PrintArray();


    return 0;
}
